package com.itmuch.cloud.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.SecurityFilterChain;

@Configuration
public class SecurityConfig {

    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        http
                .csrf(csrf -> csrf.disable())// 关闭 CSRF 保护（Eureka 客户端需要）
                .authorizeHttpRequests(auth -> auth // 配置请求授权规则
                        .anyRequest().authenticated()  // 所有请求都需要认证
                )
                // 启用 HTTP Basic 认证（适合 Eureka 控制台和服务注册）
                .httpBasic(httpBasic -> {
                });
        return http.build();
    }
}
